exports.controllers={
	/*
		Function: controllers.slider_images
	
		Makes an image-slider.
			
		Parameters:
			options - an object of:
			options.folder_id - optional, id from Tfile_groups
			options.group_id - optional, id from Tslider_image_groups
			options.group_code - optional, code from Tslider_image_groups
			options.group_name - optional, name from Tslider_image_groups - need one of "group_id" "group_code" or "group_name"
			options.template - optional, template to render, defaults to "slider_images/body"
			options.preview - optional, previews size, defaults to '4C'
			options.mark_width - optional, width of dot, defaults to 30
		Returns:
			Valid HTML
	*/
	slider_images: function(space,options) {
		if (options.folder_id) {
			space.slider_images=space.site.sql.execute_and_fetch("files/list_like_model",{file_group_id:options.folder_id,file_type_id:1});
			space.slider_images.forEach(function (m) {space.functions.init_file(space,m,"image_id","image_id");});
		} else {
			var grpid=space.functions.get_slider_image_group_id(space,options,"group");
			space.slider_images=space.mfact.list("slider_image",{group_id: grpid,order_by: "main.ordering",enabled:1});
		}
		if (!("preview" in options)) options.preview="4C";
		space.slider_images_px=(options.mark_width||30)*space.slider_images.length;
		space.slider_images.forEach(function(x) {
			x.preview=(options.preview=="")?x.image_id_url:space.functions.preview(space,options.preview,x.image_id_url);
		});
		return space.views.process("widgets/"+(options.template||"slider_images/body"),space);
	}
};

exports.functions={
	/*
		Function: functions.get_slider_image_group_id

		Gets group_id from either one - code, name or id of slider_image_groups

		Parameters:
			options - the hash of:
			options.PREFIX_id - optional, from Tslider_image_groups table
			options.PREFIX_code - optional, from Tslider_image_groups table
			options.PREFIX_name - optional, from Tslider_image_groups table
			prefix - a prefix to use in search of options

		Returns:
			Numeric ID or undefined
	*/
	get_slider_image_group_id:function(space,options,prefix) {
		if (!prefix) prefix="nav";
		if (options[prefix+"_id"]) return options[prefix+"_id"];
		if (options[prefix+"_code"]) return space.site.sql.execute_and_fetch_one("slider_image_groups/get_by_code",{code: options[prefix+"_code"]}).id;
		if (options[prefix+"_name"]) return space.site.sql.execute_and_fetch_one("slider_image_groups/get_by_name",{name: options[prefix+"_name"]}).id;
		return undefined;
	}
};
